/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.projects; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.util.*; import javax.swing.tree.*; import javax.swing.border.*; import org.openide.*; import org.openide.filesystems.*; import org.openide.nodes.*; import org.openide.explorer.*; import org.openide.explorer.view.*; import org.openide.util.enum.*; /** * Show bean tree view allowing selection of main class. * * @author Petr Kuzel * @version */ public class ExplorerView extends javax.swing.JPanel { private ExplorerPanel exp; private final Node root; private final String title; /** Creates new form MainClassView * @param root root node * @param selected nodes or null * @param title title of the frame */ public ExplorerView(Node root, Node[] selected, String title) { this.root = root; this.title = title; initComponents (); // add bean tree view exp = new ExplorerPanel(); exp.setLayout(new BorderLayout()); exp.setPreferredSize(new Dimension(300,350)); exp.getExplorerManager().setRootContext(root); BeanTreeView tree = new BeanTreeView(); tree.setBorder(new EtchedBorder()); tree.setPopupAllowed(false); exp.add(tree, BorderLayout.CENTER); add(exp, BorderLayout.CENTER); try { if (selected != null) { exp.getExplorerManager().setSelectedNodes(selected); } } catch (java.beans.PropertyVetoException ex) { // let nothing is selected. } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents setLayout (new java.awt.BorderLayout ()); setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(4, 4, 4, 4))); setName (title); }//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables /** Get selected nodes. * @return selected nodes */ public Node[] getSelected() { return exp.getExplorerManager().getSelectedNodes(); } // -- Some universal static method usable here -- /** Find node for given root and FileObject * @param root root node * @param fo FileObject */ public static Node getNodeFor(Node root, FileObject fo) { String name = fo.getPackageName('.'); Node n = null; StringTokenizer st = new StringTokenizer (name, "."); // NOI18N try { FileSystem fs = fo.getFileSystem (); Enumeration en = new SequenceEnumeration ( new SingletonEnumeration (fs.getSystemName()), st ); n = NodeOp.findPath (root, en); } catch (Exception ex) { if (Boolean.getBoolean ("netbeans.debug.exceptions")) ex.printStackTrace (); // NOI18N } return null; } // -- Inner classes. -- public static class DialogAcceptor implements ActionListener { public boolean ok = false; public void actionPerformed(ActionEvent e) { if (e.getSource() == DialogDescriptor.OK_OPTION) { ok = true; } } } } /* * Log * 3 Gandalf 1.2 1/13/00 Martin Ryzl heavy localization * 2 Gandalf 1.1 1/10/00 Martin Ryzl * 1 Gandalf 1.0 1/9/00 Martin Ryzl * $ */